import Mock from 'mockjs2'
import { builder, getBody } from '../util'

const patientList = []

for (var i = 1; i < 10; i++) {
  const patient = {
    id: Mock.mock('@increment'),
    name: Mock.mock('@cname'),
    carType: Mock.mock('@integer(0,2)'),
    carId: Mock.mock('@integer(100000000000000000,800000000000000000)'),
    age: Mock.mock('@integer(20,105)'),
    gender: Mock.mock('@integer(0,1)'),
    phone: Mock.mock('@integer(13100000000,18900000000)'),
    contact: Mock.mock('@cname'),
    emergency: Mock.mock('@integer(13100000000,18900000000)'),
    state: Mock.mock('@integer(0,1)'),
    department: Mock.mock('@integer(0,5)'),
    insurance: Mock.mock('@integer(0,1)'),
    allopatry: Mock.mock('@integer(0,1)'),
    doctor: Mock.mock('@cname'),
    bed: Mock.mock('@integer(101,1450)'),
    bedNum: Mock.mock('@integer(1,6)'),
    remarks: Mock.mock('@cparagraph(1,3)'),
    inDate: Mock.mock('@integer(2019,2020)-@integer(1,12)-@integer(1,28)'),
    outDate: null
  }
  patientList.push(patient)
}

const patient = () => {
  console.log('patient', patientList)
  return builder(patientList)
}

const del = (id) => {
  delete patientList[id - 1]
  return builder()
}

const add = (options) => {
  console.log('message', options)
  const body = getBody(options)
  body.id = Mock.mock('@increment')
  console.log('body', body)
  patientList.push(body)
  return builder()
}

Mock.mock(/\/patient\/data/, 'get', patient)
Mock.mock(/\/patient\/del/, 'post', del)
Mock.mock(/\/patient\/add/, 'post', add)
